import { axios } from '@/utils/request'
import api from './index'

// const api = {
//   user: '/users/sys-user',
//   role: '/role',
//   service: '/service',
//   permission: '/permission',
//   permissionNoPager: '/permission/no-pager',
//   orgTree: '/org/tree'
// }
//
// export default api

export function getUserList (parameter) {
  return axios({
    url: `${api.User}/page`,
    method: 'get',
    params: parameter
  })
}

export function getDeptTreeList(parameter) {
  return axios({
    url: `${api.Organization}/tree/list`,
    method: 'get',
    params: parameter
  })
}
export function getRoleList (parameter) {
  return axios({
    url: `${api.Role}/list`,
    method: 'get',
    params: parameter
  })
}

export function getServiceList (parameter) {
  return axios({
    url: api.ServiceList,
    method: 'get',
    params: parameter
  })
}

export function getPermissions () {
  return axios({
    url: `${api.Menu}/permission/list`,
    method: 'get',
    params: {}
  })
}

export function getUserMenuByType (userId, type) {
  return axios({
    url: `${api.Menu}/user/permission/${userId}/${type}`,
    method: 'get',
    params: {}
  })
}

export function getRoleMenuByRoleId (roleId) {
  return axios({
    url: `${api.Menu}/role/permission/${roleId}`,
    method: 'get',
    params: {}
  })
}

export function getOrgTree (parameter) {
  return axios({
    url: `${api.Organization}/page`,
    method: 'get',
    params: parameter
  })
}

export function getMenuTree (parameter) {
  return axios({
    url: `${api.Menu}/page`,
    method: 'get',
    params: parameter
  })
}

export function getMenuTreeList () {
  return axios({
    url: `${api.Menu}/tree-list`,
    method: 'get',
    params: {}
  })
}

// id == 0 add     post
// id != 0 update  put
export function saveService (parameter) {
  return axios({
    url: api.ServiceList,
    method: parameter.id === 0 ? 'post' : 'put',
    data: parameter
  })
}
